@extends('common.admin-master')

@section('html-body')
    <div class="content">

        <div class="header">
            <h1 class="page-title">案例管理</h1>
        </div>

        <div class="container-fluid">
            <div class="row-fluid">

                <div class="row-fluid">
                    <div id="TabContent" class="tab-content">
                        <div class="tab-pane fade in active" id="creater_list">
                            <div class="row-fluid">
                                <div class="block span12">
                                    <a href="#tablewidget" class="block-heading" data-toggle="collapse">开发案例列表<span
                                                class="label label-warning"></span></a>
                                    <div id="tablewidget" class="block-body collapse in">
                                        <table class="table">
                                            <thead>
                                            <tr>
                                                <th>案例id</th>
                                                <th>隶属团队</th>
                                                <th>案例名称</th>
                                                <th>案例描述</th>
                                                <th>案例链接</th>
                                                <th>状态</th>
                                                <th>操作</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            @if($exams)
                                                @foreach($exams as $exam)
                                                    <tr>
                                                        <td>{{$exam->id}}</td>
                                                        <td><a href="@if($exam->org){{route('Admin.Service.checkOrg',['id'=>$exam->org->id])}} @else# @endif">@if($exam->org){{$exam->org->org_name}}@else - @endif</a></td>
                                                        <td>{{$exam->title}}</td>
                                                        <td>@if($exam->org){{\App\Services\TextStr::strMiddleReduceWordSensitive($exam->org_desc,10,'...')}}@else - @endif</td>
                                                        <td>{{$exam->url}}</td>
                                                        <td @if($exam->state == 0)style="color: #333333" @elseif($exam->state == 1)style="color:goldenrod"@elseif($exam->state == 2)style="color: green"@else style="color:red"@endif>@if($exam->state == 0)未提交@elseif($exam->state == 1)审核中@elseif($exam->state == 2)通过审核@else审核不通过@endif</td>
                                                        <td>
                                                            <a class="edit" href="{{route('Admin.Service.checkExam',['id'=>$exam->id])}}">@if($exam->state == 2 || $exam->state == 3)查看@else审核@endif</a>|
                                                            <a class="del" href="javascript:;" data="{{$exam->id}}">删除</a>
                                                        </td>
                                                    </tr>
                                                @endforeach
                                            @endif
                                            </tbody>
                                        </table>
                                    </div>
                                    <div class="pagination">
                                        <ul>
                                            {!! $exams->render() !!}
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>

    </div>
    <script>
        jQuery(function() {
            var doc = document,
                    $doc = $(doc);

            jQuery.ajaxSetup({
                case:false,
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });

            $doc.on('click','.del',function(){
                var id = $('.del').attr('data');
                $.ajax({
                    type:"post",
                    url:"{{route('Api.Admin.delExam')}}",
                    dataType:"json",
                    data:{
                        "examid":id
                    },
                    success:function(obj){
                        if(obj.level === "success"){
                            noty({text:obj.message,type:obj.level,timeout:800,
                                callback:{
                                    afterClose:function(){
                                        location.reload();
                                    }
                                }
                            });
                        }
                    },
                    error:function(obj){
                        var datajson = obj.responseJSON;
                        noty({text:datajson.message,type:datajson.level,timeout:800});
                    }
                });
            })
        });
    </script>
@endsection